/**
 * 
 */
package metalink.admin;

import java.util.ArrayList;
import java.util.Map;
import java.util.Vector;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import model.admin.LibraryMo;

import vo.LibraryBookDetailsVo;
import vo.mixed.LibraryStudentVo;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Sony
 * 
 */
public class GetIssuedBooks extends ActionSupport {
	ArrayList<LibraryStudentVo> list;
	String view = "",yearfilter,coursefilter;

	HttpSession session;
	private int result;

	//------------ Pagination --------------//
	private int page;
    private String morepages;
	private Vector noofpages=new Vector();
	private int nextpage;
	private int currentpage;
	private String hasprevpage;
	private int prevpage;
	private int items;
	//private Vector pagelist=new Vector();
	private ArrayList<LibraryStudentVo> pagelist;
	public String execute() {

		pagelist = new ArrayList<LibraryStudentVo>();
		int flag =0;
		GetIssuedBooks gib = new GetIssuedBooks();
		gib.setView(view);
		if (view.equals("issuedbooks")) {
			list = new ArrayList<LibraryStudentVo>();
			LibraryMo mo = new LibraryMo();
			list = mo.GetIssuedBookList("issuedbooks");
			flag = 1;
		} else if (view.equals("all")) {
			list = new ArrayList<LibraryStudentVo>();
			LibraryMo mo = new LibraryMo();
			list = mo.GetIssuedBookList("all");
			flag = 1;
		}
		else if(view.equals("filterissuedbooks"))
		{
			list = new ArrayList<LibraryStudentVo>();
			LibraryMo mo = new LibraryMo();
			list = mo.GetFilteredIssuedBookList(yearfilter,coursefilter);
			flag = 1;
		}
		session = ServletActionContext.getRequest().getSession();
		session.setAttribute("view", view);
		
result = list.size();
		
		//---------- Pagination ------------------//
		
		int p=getPage();
        if(p==0)
        {
            setHasprevpage("false");
        }
        else
        {
            setHasprevpage("true");
            setPrevpage(p-1);
        }

        setCurrentpage(p);

        int count;
        count=0;

        int size=list.size();
        setItems(size);
        int pagesinlist=size/15;
        while(count<=pagesinlist)
        {
            noofpages.add(count);
            count++;
        }
        count=0;
        while(count<15)
        {

            if(size>=(p*15)+count+1)
            {
                System.out.println(p);
                pagelist.add(list.get((p*15)+count));
                System.out.println((p*15)+count);
                System.out.println("size"+pagelist.size());
                count++;
                setMorepages("true");
                setNextpage(p+1);

            }
            else
            {
                setMorepages("false");
                break;
            }
        }
		
		
        if(flag == 1)
        	return SUCCESS;
        else
        	return ERROR;
	}

	public String getView() {
		return view;
	}

	public void setView(String view) {
		this.view = view;
	}

	public ArrayList<LibraryStudentVo> getList() {
		return list;
	}

	public void setList(ArrayList<LibraryStudentVo> list) {
		this.list = list;
	}

	public String getYearfilter() {
		return yearfilter;
	}

	public void setYearfilter(String yearfilter) {
		this.yearfilter = yearfilter;
	}

	public String getCoursefilter() {
		return coursefilter;
	}

	public void setCoursefilter(String coursefilter) {
		this.coursefilter = coursefilter;
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getMorepages() {
		return morepages;
	}

	public void setMorepages(String morepages) {
		this.morepages = morepages;
	}

	public Vector getNoofpages() {
		return noofpages;
	}

	public void setNoofpages(Vector noofpages) {
		this.noofpages = noofpages;
	}

	public int getNextpage() {
		return nextpage;
	}

	public void setNextpage(int nextpage) {
		this.nextpage = nextpage;
	}

	public int getCurrentpage() {
		return currentpage;
	}

	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}

	public String getHasprevpage() {
		return hasprevpage;
	}

	public void setHasprevpage(String hasprevpage) {
		this.hasprevpage = hasprevpage;
	}

	public int getPrevpage() {
		return prevpage;
	}

	public void setPrevpage(int prevpage) {
		this.prevpage = prevpage;
	}

	public int getItems() {
		return items;
	}

	public void setItems(int items) {
		this.items = items;
	}

	public ArrayList<LibraryStudentVo> getPagelist() {
		return pagelist;
	}

	public void setPagelist(ArrayList<LibraryStudentVo> pagelist) {
		this.pagelist = pagelist;
	}
}
